home *** CD-ROM | disk | FTP | other *** search
- '--------------------------------------------------------------------------
- ' Dialog.vbs - Shows how to open and use dialogs from the WSH scripts.
- '
- ' REMARKS:
- ' - dialog resource must be located in the file that can be loaded with
- ' Win32 LoadLibrary() function (EXE, DLL, ...) or you can use empty
- ' dialog template located in the SGWINDOW.DLL module. In this case
- ' pass empty string as a first parameter for the DoModal method and
- ' string "DLG_EMPTY" as a dialog template name.
- '
- '
- ' This file is part of the SG Window.
- ' Copyright (C) 1998 Stinga
- ' All rights reserved.
- '--------------------------------------------------------------------------
- option explicit
-
- ' Messages
- const wm_CLOSE = &H0010&
- const wm_INITDIALOG = &H0110&
- const wm_COMMAND = &H0111&
-
- const LB_ADDSTRING = &H0180&
- const LB_GETCURSEL = &H0188&
- const LB_GETTEXT = &H0189&
- const LB_GETTEXTLEN = &H018A&
-
- ' Global declarations
- Dim g, dlg, rc, sResult
- Dim edit, list
- Set dlg = WScript.CreateObject("SGWindow.Window", "dlg_")
- Set g = WScript.CreateObject("SGWindow.Globals")
-
- ' Show dialog
- rc = dlg.DoModal("DlgTest.dll", "TESTDIALOG", 100, 100)
-
- Wscript.DisconnectObject dlg
- Set dlg = Nothing
- Set g = Nothing
-
- MsgBox sResult
- WScript.Quit
-
- '--------------------------------------------------------------------------
- ' Dialog window procedure
- '--------------------------------------------------------------------------
- Sub dlg_Message(msg, wParam, lParam, result)
- result = 0
- select case msg
- case wm_INITDIALOG
- Set edit = dlg.Children("{ID}100")
- Set list = dlg.Children("{ID}105")
-
- ' Initialize dialog controls
- edit.Text = "This is edit box"
- list.SendMessage LB_ADDSTRING, 0, g.DataPtr("Item 1")
- list.SendMessage LB_ADDSTRING, 0, g.DataPtr("Item 2")
-
- case wm_CLOSE
- sResult = "Closed"
- dlg.EndDialog 3
-
- case wm_COMMAND
- Dim bHandled
- bHandled = OnCommand(g.HighWord(wParam), g.LowWord(wParam), lParam)
- if Not bHandled Then
- result = dlg.CallWindowProc(msg, wParam, lParam)
- end if
-
- case else
- result = dlg.CallWindowProc(msg, wParam, lParam)
- end select
- End Sub
-
- '--------------------------------------------------------------------------
- ' Handle dialog WM_COMMAND messages
- '--------------------------------------------------------------------------
- Private Function OnCommand(notifyCode, id, hwnd)
- OnCommand = false
- select case id
- case 1 ' OK
- ' Get text from the edit box
- sResult = "Edit box text is '" & edit.Text & "'"
-
- ' Get slected item from the list box
- sResult = GetSelText(list)
- dlg.EndDialog 1
- OnCommand = True
-
- case 2 ' CANCEL
- sResult = "Canceled"
- dlg.EndDialog 2
- OnCommand = True
-
- case 100 ' EditBox
- end select
- End Function
-
- '--------------------------------------------------------------------------
- ' Return text of the selected item for the specified list box
- '--------------------------------------------------------------------------
- Private Function GetSelText(list)
- Dim nSel, s
- nSel = list.SendMessage(LB_GETCURSEL, 0, 0)
- s = Space(list.SendMessage(LB_GETTEXTLEN, 0, 0) + 1)
- list.SendMessage LB_GETTEXT, nSel, g.DataPtr(s)
- GetSelText = s
- End Function
-
-